package com.sniff.atp.modules.test.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sniff.atp.common.api.CommonPage;
import com.sniff.atp.common.api.CommonResult;
import com.sniff.atp.modules.test.model.MobilePhone;
import com.sniff.atp.modules.test.service.MobilePhoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.modules.test.controller
 * @Author: zxy
 * @CreateTime: 2023-11-27 11:04
 * @Description:
 * @Version: 1.0
 */

@RestController
@RequestMapping("/test/mobilePhone")
@Api(value = "手机管理", tags = "手机管理")
public class MobilePhoneController {
    @Autowired
    private MobilePhoneService mobilePhoneService;

    @ApiOperation("新增手机")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult mobilePhoneCreate(@RequestBody MobilePhone mobilePhone) {

        boolean success = mobilePhoneService.create(mobilePhone);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("修改手机")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@RequestBody MobilePhone mobilePhone) {

        boolean success = mobilePhoneService.update(mobilePhone);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("手机列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult mobilePhoneList(@RequestBody MobilePhone mobilePhone) {

        if(mobilePhone.getPageSize() == null){
            mobilePhone.setPageSize(10);
        }
        if(mobilePhone.getPageNum() == null){
            mobilePhone.setPageNum(1);
        }
        Page<MobilePhone> menuList = mobilePhoneService.list(mobilePhone, mobilePhone.getPageSize(), mobilePhone.getPageNum());
        return CommonResult.success(CommonPage.restPage(menuList));
    }

}
